package com.farsunset.cim.client.android;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.handler.timeout.IdleStateHandler;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timer;

public class MessageClientPipelineFactory implements ChannelPipelineFactory {
	static Timer timer = new HashedWheelTimer(); 
    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = Channels.pipeline();
        
        pipeline.addLast("decoder", new MessageDecoder(Integer.MAX_VALUE, 1,4));
        pipeline.addLast("encoder", new MessageEncoder());
        pipeline.addLast("handler", new MessageClientHandler());
        pipeline.addLast("timeout", new IdleStateHandler(timer, 30, 30, 50));//此两项为添加心跳机制 10秒查看一次在线的客户端channel是否空闲，IdleStateHandler为netty jar包中提供的类 
        pipeline.addLast("hearbeat", new Heartbeat());//此类 实现了IdleStateAwareChannelHandler接口 

        //netty会定时扫描 空闲的channel 
        //pipeline.addFirst("testClientDownHandlerA", new TestClientDownHandlerA());
        //pipeline.addFirst("testClientDownHandlerB", new TestClientDownHandlerB());
        
        return pipeline;
    }
}